package com.ruoyi.project.order.service.impl;

import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.order.domain.HisOrderCharge;
import com.ruoyi.project.order.domain.HisOrderChargeItem;
import com.ruoyi.project.order.service.HisOrderChargeItemService;
import com.ruoyi.project.order.service.HisOrderChargeService;
import com.ruoyi.project.order.service.HisOrderPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class HisOrderPayServiceImpl implements HisOrderPayService {


    @Autowired
    private HisOrderChargeService orderChargeService;

    @Autowired
    private HisOrderChargeItemService orderChargeItemService;

    @Transactional
    @Override
    public AjaxResult addOrder(HisOrderCharge ordercharge, List<HisOrderChargeItem> orderChargeItemList) {
        int i = 0;
             i =  orderChargeService.insertOrderCharge(ordercharge);
        for (HisOrderChargeItem hisOrderChargeItem : orderChargeItemList) {
            hisOrderChargeItem.setOrderId(ordercharge.getOrderId());
            orderChargeItemService.insertHisOrderChargeItem(hisOrderChargeItem);
        }
        if (i > 0){
            return AjaxResult.success("支付成功");
        }

        return AjaxResult.error("支付失败");
    }
}
